import React from 'react'


interface State {
    hasError: Boolean
}


export default class ErrorBoundary extends React.Component<any, State> {
    constructor(props: {} | Readonly<{}>) {
        super(props);
        this.state = { hasError: false };
    }

    static getDerivedStateFromError(error: any) {
        return { hasError: true };
    }

    componentDidCatch(error: any, info: any) {
        console.log(error, info);
    }

    render() {
        if (this.state.hasError) {
            return <h1>页面发生错误</h1>;
        }
        return this.props.children;
    }
}